/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦，本文采用木兰宽松许可证第2版]
 * 
 * https://zhiqim.org/project/zhiqim_kit/zhiqim_git.htm
 *
 * ZhiqimGit is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.git.command;

import java.io.File;
import java.util.concurrent.Callable;

import org.zhiqim.git.Git;
import org.zhiqim.git.GitConstants;

import org.zhiqim.kernel.util.Asserts;

/**
 * 初始化命令
 * https://www.kernel.org/pub/software/scm/git/docs/git-init.html
 *
 * @version v1.0.0 @author zouzhigang 2017-4-24 新建与整理
 */
public class InitCommand implements Callable<Git>, GitConstants
{
    private File directory;         //仓库目录
    private boolean bare;           //是否裸仓库，（只有git描述目录，即不含文件和文件夹信息）
    private String name;
    private String email;

    /******************************************************************************/
    //设置参数
    /******************************************************************************/
    
    /** 设置是否裸仓库 */
    public InitCommand setBare(boolean bare)
    {
        this.bare = bare;
        return this;
    }
    
    /** 设置仓库目录，裸仓库时为${gitMetaDir}，非裸仓库为${gitWorkDir}，${gitMetaDir}=${gitWorkDir}/.git */
    public InitCommand setDirectory(File directory)
    {
        this.directory = directory;
        return this;
    }
    
    /** 初始化作者名称 */
    public InitCommand setName(String name)
    {
        this.name = name;
        return this;
    }
    
    /** 初始化作者邮箱 */
    public InitCommand setEmail(String email)
    {
        this.email = email;
        return this;
    }
    
    /******************************************************************************/
    //调用
    /******************************************************************************/
    
    @Override
    public Git call() throws Exception
    {
        Asserts.assertNotNull(directory, "初始化仓库时，目录不能为空");
        Asserts.assertNotEmpty(name, "初始化仓库时，作者名称不能为空");
        Asserts.assertNotEmpty(email, "初始化仓库时作者邮箱不能为空");
        
        return new Git(directory, bare).create(name, email);
    }
}
